<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/common/common.jsp"%>
<script type="text/javascript" >
var editor = "null";	
//附件ID
var newFilesIdAttrs = [];
$(function(){
	$('#newsMsg').bind('focus',function(){
		if('null'==editor){
			editor = KindEditor.create('#newsMsg', {
				basePath:ctx+'/ui/kindeditor/',
			    uploadJson : ctx + '/ui/kindeditor/jsp/upload_json.jsp',
			    fileManagerJson : ctx + '/ui/kindeditor/jsp/file_manager_json.jsp',
			    allowFileManager : true
			    //items:[
			    //       'source','|', 'preview', 'cut', 'copy', 'paste',
			    //       'plainpaste', 'wordpaste', '|', 'justifyleft', 'justifycenter', 'justifyright',
			    //       'justifyfull', 'insertorderedlist', 'insertunorderedlist', 'indent','outdent','quickformat',
			    //       'selectall','formatblock','fontname','fontsize','forecolor','hilitecolor','bold','italic'
			    //]
			});
		}
	});
	
	$('#newsSave').bind('click',function(){
		//让 编辑器吧数据保存在文本域中
		if('null'!=editor){
			editor.sync();
		}
		$('#newFilesId').val(newFilesIdAttrs);
		CQOA.formSubmit($('#bulletinOperateForm'),ctx+'/pof/Bulletin!save.action',function(o){
			if(o.success){
				comeback();
				$('#bulletinGrid').datagrid('reload');
			}
			$.messager.show({
				msg : o.msg
			});
		},{});
	});
	
	$('#operationNews').combobox({
		onChange:function(node,oldNode){
			if('1'==node){
				CQOA.hideDiv('selectViewer');
				$('#scopesIds').val('0');
				$('#viewer').val('全单位');
			}else{
				CQOA.showDiv('selectViewer');
				$('#scopesIds').val('');
				$('#viewer').val('');
				
			}
		},
		onSelect:function(node){
			//console.log(node);
		}
	});
	//选择人员
	$('#selectViewBtn').bind('click',function(){
		var operation = $('#operationNews').combobox('getValue');
		if('4'==operation){
			CQOA.load('targetPopup',ctx + '/sm/User!userSelect.action',{},function(){
				showHideFun('targetPopup','open');
			});
		}else if('3'==operation){
			
		}else if('2'==operation){
			
		}
	})
	
	
	$('#newsUpload').bind('click',function(){
		  //默认是附件
	    var isTypes = 2;
	    var targetTableSid = "";
	    //0 正式  1 临时
	    var isTempFile = 1;
	    var attachmentType = "doc|xls|gif|txt|zip|rar|jpg|pdf";//附件类型
	    var attachmentNumber =10;
	    var attachmentSize = 20;
	    var values = 1024 * 1024;
	    /**
	     * 文件上传菜单
	     * @param {Object} businessObject 业务对象名
	     * @param {Object} targetTableSid 业务数据SID(OPTIONAL)
	     * @param {Object} types 附件类型
	     * @param {Object} isTempFile 是否临时文件
	     * @param {Object} url 上传的URL
	     * @param {Object} allowedFileTypes  允许的文件内容,以|分隔 gif|jpg
	     * @param {Object} allowedSingleFileSize 允许上传的个文件大小
	     * @param {Object} callback 回调function
	     * @param {Object} maxLength 允许上传的文件数
	     */
	    fn_fileupload("News", targetTableSid, isTypes, isTempFile, attachmentType, attachmentSize * values, attachmentNumber, function(data){
	    	for (var i = 0; i < data.length; i++) {
	    		var downLoadUrl = '<a href="#" onClick="downloadFun('+data[i].sid+');" style="color:blue;">' + data[i].cname + '</a>';
	    		var delUrl = '<a href="#" onClick="deleteAttr('+data[i].sid+');" style="color:blue;">【删除】</a>';
	    		$('#newFiles').append("<p id='attache" + data[i].sid + "'>" + downLoadUrl + " " + delUrl + "</p>");
	    		newFilesIdAttrs.push(data[i].sid);
	    	}
	    });
});
})	

CQOA.targetPopup = function(rows,option){
	var userIds='';
	var userNames='';
	for(var i=0;i<rows.length;i++){
		var id = rows[i].id;
		if (id.substr(0,1)=='u') 
			id=id.substr(1);
		if(userIds.length<1){
			userIds = id;
			userNames = rows[i].text;
		}else{
			userIds = userIds+','+id;
			userNames =userNames+','+rows[i].text;
		}
	}
	$('#scopesIds').val(userIds);
	$('#viewer').val(userNames);
	
};

/**
 * 删除附件信息
 */
function deleteAttr(id){
	deleteFile(id,function(){
		 $("#attache" + id).remove();
		 newFilesIdAttrs.remove(id);
	});
};
</script>
<div id="easyui-title" style="display:none">
	 公告管理
</div>
<div style="height: 30px;text-align: center;">
	<a href="#" class="easyui-linkbutton" iconCls="icon-back" onclick="comeback();">返回</a>
    <a href="#" class="easyui-linkbutton" iconCls="icon-save" id="newsSave">保存</a>
</div>
<s:form id="bulletinOperateForm">
<div style="overflow: auto;">
<s:hidden name="dto.bulletin.sid" id="bulletinId"></s:hidden>
<table class="dataTable" >
	<tr>
		<td width="80px">标题:</td>
		<td width="80%" colspan="3">
		<s:textfield name="dto.bulletin.title"  cssClass="easyui-validatebox" style="width:90%"  validType="length[1,200]" notnull="true" />
		</td>
	</tr>
	<tr>
		<td width="80px">有效时间:</td>
		<td width="40%" >
		<s:textfield name="dto.bulletin.beginTime"  cssClass="easyui-datetimebox" style="width:200px;"   />
		</td>
		<td width="80px">至:</td>
		<td width="40%" >
		<s:textfield name="dto.bulletin.endTime"  cssClass="easyui-datetimebox" style="width:200px;"   />
		</td>
	</tr>
	<tr>
		<td width="80px">允许查看:</td>
		<td width="80%" colspan="3">
		<s:select name="dto.operation" id="operationNews" list="#{1:'全单位',2:'部门',3:'岗位',4:'人员'}" cssClass="easyui-combobox" style="width:200px;" ></s:select>
		<span id="selectViewer" style="display: none;">
			<a href="#" class="easyui-linkbutton" id="selectViewBtn" >选择</a>
		</span>
		<br>
		<s:hidden name="dto.scopes" id="scopesIds"></s:hidden>
		<s:textarea id="viewer" name="dto.scopeCnames"  cssClass="easyui-validatebox" style="width:90%" rows="8" readonly="true" validType="length[1,4000]" />
		</td>
	</tr>
	<tr>
		<td width="80px">附件:</td>
		<td width="80%" colspan="3">
		 <a href="#" class="easyui-linkbutton" id="newsUpload">上传附件</a>
		 <s:hidden id="newFilesId" name="dto.fileIds"></s:hidden>
		 <p id="newFiles">
		 	<s:iterator value="dto.smFiles" id='filement' var="filement">
		          <a  id="attache${filement.sid}" style="color: blue;" href="#" onClick="downloadFun(${filement.sid});" >${filement.cname}</a>
		          <a  style="color: blue;" href="#" onClick="deleteAttr(${filement.sid});" >【删除】</a>
		          <br />
	        </s:iterator>
		 </p>
		</td>
	</tr>
	<tr>
		<td width="80px">内容:</td>
		<td width="80%" colspan="3">
		<s:textarea id="newsMsg" name="dto.bulletin.content"  cssClass="easyui-validatebox" style="width:90%" rows="20" validType="length[1,4000]" />
		</td>
	</tr>
</table>
</div>
</s:form>
